document.getElementById("footer-year").innerText = new Date().getFullYear();
let themeMode = sessionStorage.getItem("theme-mode");

layui.use(function () {
    const form = layui.form, $ = layui.$;

    $('.ws-menu-phone').click(function () {
        $('.ws-menu-phone-list').addClass('show');
        document.body.style.overflow = 'hidden';
    });
    $('.ws-menu-phone-close').click(() => {
        $('.ws-menu-phone-list').removeClass('show');
        document.body.style.overflow = '';
    });

    $('.no-referrer').click(function () {
        let target = $(this).data().target;
        layer.open({
            title: $(this).data().title ? [$(this).data().title, 'font-size:18px;'] : false,
            type: 1,
            area: ['500px', 'auto'], // 宽高
            content: $(target).html(),
            anim: 'slideDown',
            closeBtn: 0,
            // offset:'t',
            btn: ['关闭'],
            resize: false,
            scrollbar: false,
            skin: `ws-layer-` + target.substring(1),
        });
    });


    $('.layui-fixbar .layui-fixbar-top').click(() => {
        window.scrollTo({
            top: 0,
            behavior: "smooth"
        });
    });
    $(() => {
        theme();
        if (document.body.scrollTop > 200 || document.documentElement.scrollTop > 200) {
            $('.layui-fixbar').show();
        }

    });

    window.onscroll = function () {
        if (document.body.scrollTop > 200 || document.documentElement.scrollTop > 200) {
            $('.layui-fixbar').show();
        } else {
            $('.layui-fixbar').hide();
        }
    };

    function theme() {

        if (themeMode === 'dark') {
            form.val('form', {'themeMode': 'off'});
            $('.ws-theme-icon').removeClass('layui-icon-moon').addClass('layui-icon-light');
            $('body').eq(0).addClass('dark');
        }
    }


    layui.code({
        elem: 'pre',
        theme: "dark",
        // langMarker:true,
        ln: true,
        codeRender: function (code, opts) {
            return hljs.highlight(code, {language: opts.lang}).value;
        }
    });
    $('.ws-theme-icon-btn').click(function () {
        $('.ws-header-tool .layui-form-switch').click();
    });

    form.on('switch(header-theme-mode)', (data) => {
        if (data.elem.checked) {
            sessionStorage.setItem("theme-mode", 'dark');
            $('.ws-theme-icon').removeClass('layui-icon-moon').addClass('layui-icon-light');
            themeMode = 'dark';
            $('body').eq(0).addClass('dark');
        } else {
            sessionStorage.setItem("theme-mode", 'light');
            $('.ws-theme-icon').addClass('layui-icon-moon').removeClass('layui-icon-light');
            themeMode = '';
            $('body').removeClass('dark');
        }
    });
});